{% extends "base.html" %}
{% load static from staticfiles %}

{% block content %}


{% if error_messages %}
<h1>Errors</h1>
<ul>
{% for error in error_messages %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}


{% if is_result %}

{% if preferred_label %}
<h1>Fuzzy search result variants for concept <strong><i>{{preferred_label}}</i></strong> within indexed documents (corpus)</h1>
{% else %}
<h1>Fuzzy search result variants for searched concept(s) within indexed documents (corpus)</h1>
{% endif %}

{% if aggregation_new %}

<h2>Suggestions (not yet assigned to the concept entry in thesaurus)</h2>
Suggestions of potential additional variants of all labels, alternate labels and hidden labels based on enabled stemmers, compounded words by wildcards and fuzzy search results by edit distance:

<ul>

{% for result, values in aggregation_new.items %}

<li>
<h3>{{ result }}</h3>
<p>Variant occurs in <strong>{{values.count}}</strong> documents (additional <strong>+{{values.diff}}</strong> documents found by this variant, since not including a yet known variant)</p>
<p>
<a target="_blank" href="{% url 'thesaurus:api' %}?id={{entity_id}}&relation=altLabel&label={{result}}">[Add to alternate labels, aliases or synonyms]</a>
|
<a target="_blank" href="{% url 'thesaurus:api' %}?id={{entity_id}}&relation=hiddenLabel&label={{result}}">[Add to hidden labels or misspellings]</a>
|
 Todo: [Add as broader concept] | [Add as narrower concept] | [Exclude (false positive)]
</p>
</li>

{% endfor %}
</ul>

{% else %}

<p>No new variants found.</p>

{% endif %}


<a class="tiny button" id="show_analysis" onclick="document.getElementById('analysis').style.display = 'block'; document.getElementById('show_analysis').style.display = 'none';">Show details of the analysis leading to this recommendations</a>

<div id="analysis" style="display: none;">

<h2>Aggregation of analysis results</h2>
Aggregated variants of all labels, alternate labels and hidden labels and all stemmers, compounded words and fuzzy search by edit distance:

<ul>

{% for result in aggregation %}

<li>{{ result }}</li>


{% endfor %}
</ul>



<p>This aggregate is result of all following search operations.</p>

<p>Warning:</p>

<p>For better performance only variants from documents were considered, that do not contain the known variant (and so are found by standard search with AND operator without the additional variant, too).</p>

<p>Additionally, all variants that were found by a former another search/analysis method, will not be searched again in further steps with other analysis methods, so some found variants that were found and included in the agregated overview are missing for the separated list of some methods, even if this method would find them, too.
If you want to analyze which variants are found by only one method/stemmer/analyzer, swich off all other options.</p>

{% for result, values in results.items %}

<h1>Analysis of <i>{{ result }}</i></h1>

{% for stemmer, stemmed_values in values.items %}

<h2>Analysis of <i>{{ result }}</i> by <i>{{stemmer}}</i></h2>



	{% if stemmed_values %}
		<ul>
		{% for stemmed in stemmed_values %}

			<li>{{ stemmed }}</li>


		{% endfor %}
		</ul>

	{% else %}
	
			<p>No results.</p>
				
	{% endif %}

{% endfor %}

{% endfor %}



</div>




<hr/>

{% endif %}



<h1>Search for variants of following terms or names</h1>

<form action="" method="post">{% csrf_token %}



    <div class="fieldWrapper">
        <label for="id_list">Known variant(s) (one entry per line):</label>
        {{ form.list }}
        {{ form.list.errors }}

    </div>


<input class="button" type="submit" value="Search for additional variants of each list entry" />


<div class="row">


    <div class="small-12 medium-8 columns">

	<h3>Similarity and misspellings by low edit distance (Levensthein distance)</h3>

        {{ form.similar }}
        <label for="similar">Low edit distance</label>

			(Example: Search for <i>misspelling</i> would find <i>misspelign</i> or some OCR failures in scanned documents)
        
        <h3>Compounded words</h3>
			
		<div>
        {{ form.prefix }}
        <label for="prefix">Prefix wildcard</label>
        (Example: Search for <i>walk</i> would find <i>sleepwalk</i>)
        
      </div>
		<div>
        {{ form.suffix }}
        <label for="suffix">Suffix wildcard</label>
        (Example: Search for <i>sleep</i> would find <i>sleepwalk</i>)
      </div>

<h3>Proximity</h3>

Todo.

(Example: Search for <i>Barack Obama</i> would find <i>Barack Hussein Obama</i>)
 
	</div>



    <div class="small-12 medium-4 columns">

	<h3>Filter query</h3>
		<div>
        {{ form.filterquery.errors }}
        <label for="id_filterquery">Additional filter query:</label>
        {{ form.filterquery }}
<p>Results have to match this additional query part, too. So its not enough to match only the search entry of the list.</p>
<p>I.e. for filtering with additional criterias like a path, person or project name. Or to search only in some documents, data or context.</p>
    	</div>
    	
    	
    </div>





</div>

</form>

</div>
{% endblock content %}